package com.ymm.controller;

import com.ymm.domain.dto.UserDto;
import com.ymm.domain.entity.User;
import com.ymm.domain.vo.ResponseResult;
import com.ymm.service.LoginService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 椰咩咩咩
 * @version 1.0-SNAPSHOT
 * @date 2023/3/31 0:33
 * @Description
 */
@RestController
@RequestMapping("/user")
public class LoginController {

    @Resource
    private LoginService loginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user) {
        return loginService.login(user);
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @GetMapping("/getInfo")
    public ResponseResult getInfo() {
        return loginService.getInfo();
    }

    @GetMapping("/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

    /**
     * 获取路由信息，用于动态渲染路由
     *
     * @return
     */
    @GetMapping("/getRouters")
    public ResponseResult getRouters() {
        return loginService.getRouters();
    }

    @PostMapping("/register")
    public ResponseResult registerUser(@RequestBody UserDto userDto) {
        return loginService.registerUser(userDto);
    }

}
